package ${serviceImplPackage};

import com.hdac.fms.sys.common.utils.UUIDUtil;
import com.hdac.fms.sys.common.utils.StringUtil;
import com.hdac.fms.sys.common.vo.PaginationVO;
import org.springframework.stereotype.Service;
import ${servicePackage}.${modelNameUpperCamel}Service;
import ${mapperPackage}.${modelNameUpperCamel}Mapper;
import ${modelPackage}.${modelNameUpperCamel};
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * ${modelNameLowerCamel}服务实现类
 * Created by ${author} on ${date}.
 */
@Service
@Transactional
public class ${modelNameUpperCamel}ServiceImpl implements ${modelNameUpperCamel}Service{

    private static final Logger LOGGER = LoggerFactory.getLogger(${modelNameUpperCamel}ServiceImpl.class);

    @Autowired
    private ${modelNameUpperCamel}Mapper ${modelNameLowerCamel}Mapper;

    @Override
    public int insert(${modelNameUpperCamel} ${modelNameLowerCamel}) {
        if(StringUtil.isNull(${modelNameLowerCamel}.get${primaryKeyNameUpperFirst}())){
            String uuid32 = UUIDUtil.getUUID32();
            ${modelNameLowerCamel}.set${primaryKeyNameUpperFirst}(uuid32);
        }
        return ${modelNameLowerCamel}Mapper.insert(${modelNameLowerCamel});
    }

    @Override
    public int insertSelective(${modelNameUpperCamel} ${modelNameLowerCamel})  {
        if(StringUtil.isNull(${modelNameLowerCamel}.get${primaryKeyNameUpperFirst}())){
            String uuid32 = UUIDUtil.getUUID32();
            ${modelNameLowerCamel}.set${primaryKeyNameUpperFirst}(uuid32);
        }
        return ${modelNameLowerCamel}Mapper.insertSelective(${modelNameLowerCamel});
    }

    @Override
    public int deleteById(${primaryKeyTypeAndNames})  {
        return ${modelNameLowerCamel}Mapper.deleteByPrimaryKey(${primaryKeyNames});
    }

    @Override
    public int updateByIdSelective(${modelNameUpperCamel} ${modelNameLowerCamel})  {

        return ${modelNameLowerCamel}Mapper.updateByPrimaryKeySelective(${modelNameLowerCamel});
    }

    @Override
    public int updateById(${modelNameUpperCamel} ${modelNameLowerCamel})  {
        return ${modelNameLowerCamel}Mapper.updateByPrimaryKey(${modelNameLowerCamel});
    }

    @Override
    public ${modelNameUpperCamel} getById(${primaryKeyTypeAndNames})  {
        return ${modelNameLowerCamel}Mapper.selectByPrimaryKey(${primaryKeyNames});
    }

    @Override
    public List<${modelNameUpperCamel}> findByModel(${modelNameUpperCamel} ${modelNameLowerCamel})  {
        return ${modelNameLowerCamel}Mapper.findByModel(${modelNameLowerCamel});
    }

    @Override
    public PaginationVO<${modelNameUpperCamel}> findPageByModel(${modelNameUpperCamel} ${modelNameLowerCamel}, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum == null? 1 : pageNum, pageSize == null? 10 : pageSize);
        List<${modelNameUpperCamel}> quesList = ${modelNameLowerCamel}Mapper.findByModel(${modelNameLowerCamel});
        PageInfo<${modelNameUpperCamel}> pageInfo = new PageInfo<>(quesList);
        PaginationVO<${modelNameUpperCamel}> paginationVo = new PaginationVO(pageInfo.getTotal(), pageInfo.getList());
        return paginationVo;
    }


}
